package com.fz.us.oa.web.controller.com;

import com.fz.us.admin.base.bean.search.rule.Rule;
import com.fz.us.admin.base.bean.search.rule.RuleHelper;
import com.fz.us.admin.base.utils.DataUtil;
import com.fz.us.admin.company.entity.User;
import com.fz.us.admin.company.service.UserService;
import com.fz.us.admin.dict.entity.Dict;
import com.fz.us.admin.dict.entity.DictItem;
import com.fz.us.base.bean.BaseEnum;
import com.fz.us.oa.core.entity.com.*;
import com.fz.us.oa.core.service.com.DirectorService;
import com.fz.us.oa.core.service.com.PersonService;
import com.fz.us.oa.core.service.com.ResidentService;
import com.fz.us.oa.web.controller.BaseController;
import com.fz.us.oa.web.shiro.bind.annotation.CurrentUser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.DecimalFormat;
import java.util.*;

/**
 * Created by dzw on 2018/3/21.
 * 接口数据
 */
@Controller
@RequestMapping("/com/interface")
public class InterFaceController extends BaseController {
    private static final long serialVersionUID = -665014050091886682L;

    @Autowired
    private PersonService personService;
    @Autowired
    private DirectorService directorService;
    @Autowired
    private ResidentService residentService;

    /**
     * 统计总汇（书记）
     */
    @RequestMapping(value = "sjSummary", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object sjSummary(){
        DecimalFormat df = new DecimalFormat("0.00%");

        Map<String, Object> data = new HashMap<String, Object>();
        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;

        int num01c = 0;
        int num02c = 0;
        int num03c = 0;
        int num04c = 0;
        int num05c = 0;
        int num06c = 0;
        int num09c = 0;
        int num11c = 0;
        int num13c = 0;
        int num15c = 0;
        int num16c = 0;
        int num17c = 0;
        int num18c = 0;
        int num19c = 0;
        int num20c = 0;
        int num23c = 0;
        int num25c = 0;
        int age = 0;
        int ageBeixuan = 0;

        User user = userService.getAll().get(0);

        List<DictItem> streetList = getDictItems(user, "street");
        int i=0;
        for(DictItem street:streetList){
            i++;
            int residentCount = personService.getResidentCountByStreet(street); //居民区党组织数

            Map<String, Object> params = new HashMap<String, Object>();
            params.put("street", street);
            params.put("state", BaseEnum.StateEnum.Enable);
            params.put("generalDict", getGeneralBefore());
            List<Person> personList = personService.getList(params);

            int juminqu = 0; //居民区书记总人数
            int yijiantiao = 0; //一肩挑人数
            int niyijiantiao = 0; //拟一肩挑人数
            int nvxing = 0; //女性人数
            int allAge = 0; //年龄之和
            int dazhuan = 0; //大专以上学历人数
            int quanrizhi = 0; //全日制人数
            int tuixiufanpin = 0; //退休返聘人数

            int beixuan = 0; //备选书记人数
            int nimingque = 0; //拟明确备选居民区人数
            int weimingque = 0; //未明确备选居民区人数（备选书记人数 - 拟明确备选居民区人数）
            int shujiniyijiantiao = 0; //拟一肩挑人数
            int shujinvxing = 0; //书记女性人数
            int shujiAllAge = 0; //书记年龄总和
            int shujidazhuan = 0; //书记大专以上人数
            int shujiquanrizhi = 0; //书记全日制人数



            for(Person person:personList){

                if(person.getPersonNature()==null){
                    continue;
                }

                if(person.getShoulder()==1){ //拟一肩挑人数（备选书记的拟一肩挑人数 也就是查找所有的 拟一肩挑备选）
                    if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("拟一肩挑备选")){
                        shujiniyijiantiao++; //拟一肩挑人数
                    }
                }

                String thisPersonNature = person.getPersonNature()!=null?person.getPersonNature().getValue():"";
                if(!"shujihoubei".equals(thisPersonNature)){
                    //居民区书记人员
                    juminqu++;

                    if(person.getShoulder()==1){
                        if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("已一肩挑")){
                            yijiantiao++; //一肩挑人数
                        }
                        if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("拟一肩挑连任")){
                            niyijiantiao++; //拟一肩挑人数
                        }
                    }

                    if("女".equals(person.getGender())){ //女性人数
                        nvxing++;
                    }

                    allAge+=getSummaryAge(person.getBirthday());
                    age+=getSummaryAge(person.getBirthday());

                    String thisEdu = person.getHighEdu()!=null?person.getHighEdu().getValue():""; //大专以上人数
                    if("edu4".equals(thisEdu) || "edu5".equals(thisEdu) || "edu6".equals(thisEdu)){
                        dazhuan++;
                        String allDayText = person.getAllDayEdu()!=null?person.getAllDayEdu().getValue():"";
                        if(allDayText.equals(thisEdu)){ //其中全日制人数
                            quanrizhi++;
                        }
                    }

                    if("tuixiufanpin".equals(thisPersonNature)){ //退休返聘人数
                        tuixiufanpin++;
                    }

                }else{
                    //备选书记人员
                    beixuan++;

                    if(person.getResident()!=null){
                        nimingque++; //拟明确备选居民区人数
                    }else{
                        weimingque++; //未明确备选居民区人数
                    }

                    if("女".equals(person.getGender())){ //女性人数
                        shujinvxing++;
                    }

                    shujiAllAge+=getSummaryAge(person.getBirthday());
                    ageBeixuan+=getSummaryAge(person.getBirthday());

                    String thisEdu = person.getHighEdu()!=null?person.getHighEdu().getValue():""; //大专以上人数
                    if("edu4".equals(thisEdu) || "edu5".equals(thisEdu) || "edu6".equals(thisEdu)){
                        shujidazhuan++;
                        String allDayText = person.getAllDayEdu()!=null?person.getAllDayEdu().getValue():"";
                        if(allDayText.equals(thisEdu)){ //其中全日制人数
                            shujiquanrizhi++;
                        }
                    }
                }
            }

            rMap = new HashMap<String, Object>();
            rMap.put("id", i);
            rMap.put("street", street.getName());
//            rMap.put("streetId", street.getId());
            rMap.put("num01", residentCount);
            num01c+=residentCount;

            rMap.put("num02", street.getDescription());
            num02c+=Integer.parseInt(street.getDescription());

            rMap.put("num03", juminqu);
            num03c+=juminqu;

            rMap.put("num04", yijiantiao);
            num04c+=yijiantiao;

            rMap.put("num05", niyijiantiao);
            num05c+=niyijiantiao;

            rMap.put("num06", nvxing);
            num06c+=nvxing;

            rMap.put("num09", dazhuan);
            num09c+=dazhuan;

            rMap.put("num11", quanrizhi);
            num11c+=quanrizhi;

            rMap.put("num13", tuixiufanpin);
            num13c+=tuixiufanpin;

            if(juminqu==0){
                rMap.put("num07", "0%");
                rMap.put("num08", "0");
                rMap.put("num10", "0%");
                rMap.put("num12", "0%");
                rMap.put("num14", "0%");
                rMap.put("num15", "0");
            }else{
                BigDecimal nvxingB = new BigDecimal(nvxing);
                BigDecimal juminquB = new BigDecimal(juminqu);
                BigDecimal bai = nvxingB.divide(juminquB,4,BigDecimal.ROUND_HALF_UP); //女性比例
                rMap.put("num07", df.format(bai));

                if(allAge==0){
                    rMap.put("num08", "0");
                }else{
                    BigDecimal allAgeB = new BigDecimal(allAge);
                    BigDecimal ageAvg = allAgeB.divide(juminquB,2,BigDecimal.ROUND_HALF_UP);
                    rMap.put("num08", ageAvg);
                }

                BigDecimal dazhuanB = new BigDecimal(dazhuan);
                BigDecimal dazhuanBai = dazhuanB.divide(juminquB,4,BigDecimal.ROUND_HALF_UP); //大专比例
                rMap.put("num10", df.format(dazhuanBai));

                BigDecimal quanrizhiB = new BigDecimal(quanrizhi);
                BigDecimal quanruzhiBai = quanrizhiB.divide(juminquB,2,BigDecimal.ROUND_HALF_UP); //全日制比例
                rMap.put("num12", df.format(quanruzhiBai));

                BigDecimal tuixiufanpinB = new BigDecimal(tuixiufanpin);
                BigDecimal tuixiufanpinBai = tuixiufanpinB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP);
                rMap.put("num14", df.format(tuixiufanpinBai)); //退休返聘比例

                BigDecimal cB = new BigDecimal(residentCount).multiply(new BigDecimal(0.3));
                BigDecimal rs = tuixiufanpinB.subtract(cB);
                BigDecimal reC = rs.setScale(0, BigDecimal.ROUND_UP);
                int huan = Integer.parseInt(reC.toString());
                rMap.put("num15", huan<0?"0":huan); //换届人数 （退休返聘人数 - 街道下的居民区数量 * 0.3）


                num15c+=(Integer.parseInt(rs.setScale(0, BigDecimal.ROUND_UP).toString()));
            }


            rMap.put("num16", beixuan); //备选书记人数
            num16c+=beixuan;

            rMap.put("num17", nimingque); //拟明确备选书记数
            num17c+=nimingque;

            rMap.put("num18", weimingque); //为明确备选书记数
            num18c+=weimingque;

            rMap.put("num19", shujiniyijiantiao); //书记 拟一肩挑人数
            num19c+=shujiniyijiantiao;

            rMap.put("num20", shujinvxing); //女性书记人数
            num20c+=shujinvxing;

            rMap.put("num23", shujidazhuan); //书记大专以上人数
            num23c+=shujidazhuan;

            rMap.put("num25", shujiquanrizhi); //书记全日制人数
            num25c+=shujiquanrizhi;

            if(beixuan==0){
                rMap.put("num21", "0%");
                rMap.put("num22", "0");
                rMap.put("num24", "0%");
                rMap.put("num26", "0%");
            }else{
                BigDecimal beixuanB = new BigDecimal(beixuan);
                BigDecimal shujinvxingB = new BigDecimal(shujinvxing);
                BigDecimal shujinvxingBai = shujinvxingB.divide(beixuanB,4,BigDecimal.ROUND_HALF_UP);
                rMap.put("num21", df.format(shujinvxingBai)); //书记女性比例

                if(shujiAllAge==0){
                    rMap.put("num22", "0");
                }else{
                    BigDecimal shujiAllAgeB = new BigDecimal(shujiAllAge);
                    BigDecimal shujiAvgAge = shujiAllAgeB.divide(beixuanB,2,BigDecimal.ROUND_HALF_UP);
                    rMap.put("num22", shujiAvgAge); //书记平均年龄
                }

                BigDecimal shujidazhuanB = new BigDecimal(shujidazhuan);
                BigDecimal shujidazhuanBai = shujidazhuanB.divide(beixuanB,4,BigDecimal.ROUND_HALF_UP);
                rMap.put("num24", df.format(shujidazhuanBai)); //书记大专比例

                BigDecimal shujiquanrizhiB = new BigDecimal(shujiquanrizhi);
                BigDecimal shujiquanrizhiBai = shujiquanrizhiB.divide(beixuanB,4,BigDecimal.ROUND_HALF_UP);
                rMap.put("num26", df.format(shujiquanrizhiBai)); //书记全日制比例
            }
            dataRows.add(rMap);
        }

        //合计
        rMap = new HashMap<String, Object>();
        rMap.put("street", "合计（以拟参选数为基数）");
        rMap.put("num01", num01c);
        rMap.put("num02", num02c);
        rMap.put("num03", num03c);
        rMap.put("num04", num04c);
        rMap.put("num05", num05c);
        rMap.put("num06", num06c);
        rMap.put("num07", num03c==0?"0%":df.format(new BigDecimal(num06c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        rMap.put("num08", num03c == 0 ? "0" : new BigDecimal(age).divide(new BigDecimal(num03c), 2, BigDecimal.ROUND_UP));
        rMap.put("num09", num09c);
        rMap.put("num10", num03c==0?"0%":df.format(new BigDecimal(num09c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        rMap.put("num11", num11c);
        rMap.put("num12", num03c==0?"0%":df.format(new BigDecimal(num11c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        rMap.put("num13", num13c);
        rMap.put("num14", num03c==0?"0%":df.format(new BigDecimal(num13c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        rMap.put("num15", num15c);

        rMap.put("num16", num16c);
        rMap.put("num17", num17c);
        rMap.put("num18", num18c);
        rMap.put("num19", num19c);
        rMap.put("num20", num20c);
        rMap.put("num21", num16c==0?"0%":df.format(new BigDecimal(num20c).divide(new BigDecimal(num16c),4,BigDecimal.ROUND_UP)));
        rMap.put("num22", num16c == 0 ? "0" : new BigDecimal(ageBeixuan).divide(new BigDecimal(num16c), 2, BigDecimal.ROUND_UP));
        rMap.put("num23", num23c);
        rMap.put("num24", num16c==0?"0%":df.format(new BigDecimal(num23c).divide(new BigDecimal(num16c),4,BigDecimal.ROUND_UP)));
        rMap.put("num25", num25c);
        rMap.put("num26", num16c==0?"0%":df.format(new BigDecimal(num25c).divide(new BigDecimal(num16c),4,BigDecimal.ROUND_UP)));
        dataRows.add(rMap);

        data.put("data",dataRows);
        return ajaxJson(data);
    }



    /**
     * 统计总汇（书记）（换届后）
     */
    @RequestMapping(value = "sjSummaryAfter", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object sjSummaryAfter(){
        DecimalFormat df = new DecimalFormat("0.00%");

        Map<String, Object> data = new HashMap<String, Object>();
        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;

        int num01c = 0;
        int num02c = 0;
        int num03c = 0;
        int num04c = 0;
        int num06c = 0;
        int num09c = 0;
        int num11c = 0;
        int num13c = 0;
        int age = 0;

        User user = userService.getAll().get(0);

        List<DictItem> streetList = getDictItems(user, "street");
        int i=0;
        for(DictItem street:streetList){
            i++;
            int residentCount = personService.getResidentCountByStreet(street); //居民区党组织数

            Map<String, Object> params = new HashMap<String, Object>();
            params.put("street", street);
            params.put("state", BaseEnum.StateEnum.Enable);
            params.put("generalDict", getGeneralAfter());
            List<Person> personList = personService.getList(params);

            int juminqu = 0; //居民区书记总人数
            int yijiantiao = 0; //一肩挑人数
            int nvxing = 0; //女性人数
            int allAge = 0; //年龄之和
            int dazhuan = 0; //大专以上学历人数
            int quanrizhi = 0; //全日制人数
            int tuixiufanpin = 0; //退休返聘人数

            for(Person person:personList){

                if(person.getPersonNature()==null){ //换届后此字段（人员性质）需要有值
                    continue;
                }

                String thisPersonNature = person.getPersonNature()!=null?person.getPersonNature().getValue():"";
                if(!"shujihoubei".equals(thisPersonNature)){
                    //居民区书记人员
                    juminqu++;
                    if(person.getShoulder()==1){
                        if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("已一肩挑")){
                            yijiantiao++; //一肩挑人数
                        }
                    }

                    if("女".equals(person.getGender())){ //女性人数
                        nvxing++;
                    }

                    allAge+=getSummaryAge(person.getBirthday());
                    age+=getSummaryAge(person.getBirthday());

                    String thisEdu = person.getHighEdu()!=null?person.getHighEdu().getValue():""; //大专以上人数
                    if("edu4".equals(thisEdu) || "edu5".equals(thisEdu) || "edu6".equals(thisEdu)){
                        dazhuan++;
                        String allDayText = person.getAllDayEdu()!=null?person.getAllDayEdu().getValue():"";
                        if(allDayText.equals(thisEdu)){ //其中全日制人数
                            quanrizhi++;
                        }
                    }

                    if("tuixiufanpin".equals(thisPersonNature)){ //退休返聘人数
                        tuixiufanpin++;
                    }

                }
            }

            rMap = new HashMap<String, Object>();
            rMap.put("id", i); //序号
            rMap.put("street", street.getName()); //街道（镇）
            rMap.put("num01", residentCount); //居民区党组织数
            num01c+=residentCount;

            rMap.put("num02", street.getDescription()); //拟参加换届选举
            num02c+=Integer.parseInt(street.getDescription());

            rMap.put("num03", juminqu); //实有人数
            num03c+=juminqu;

            rMap.put("num04", yijiantiao); //一肩挑人数
            num04c+=yijiantiao;

            rMap.put("num06", nvxing); //女性
            num06c+=nvxing;

            rMap.put("num09", dazhuan); //大专以上
            num09c+=dazhuan;

            rMap.put("num11", quanrizhi); //全日制
            num11c+=quanrizhi;

            rMap.put("num13", tuixiufanpin); //退休返聘
            num13c+=tuixiufanpin;

            if(juminqu==0){
                rMap.put("num05", "0%");
                rMap.put("num07", "0%");
                rMap.put("num08", "0");
                rMap.put("num10", "0%");
                rMap.put("num12", "0%");
                rMap.put("num14", "0%");
            }else{
                BigDecimal juminquB = new BigDecimal(juminqu);

                BigDecimal yijiantiaoB = new BigDecimal(yijiantiao);
                BigDecimal yijiantiaoBai = yijiantiaoB.divide(juminquB, 4, BigDecimal.ROUND_UP);
                rMap.put("num05", df.format(yijiantiaoBai));

                BigDecimal nvxingB = new BigDecimal(nvxing);
                BigDecimal bai = nvxingB.divide(juminquB,4,BigDecimal.ROUND_HALF_UP); //女性比例
                rMap.put("num07", df.format(bai));

                if(allAge==0){
                    rMap.put("num08", "0");
                }else{
                    BigDecimal allAgeB = new BigDecimal(allAge);
                    BigDecimal ageAvg = allAgeB.divide(juminquB,2,BigDecimal.ROUND_HALF_UP); //平均年龄
                    rMap.put("num08", ageAvg);
                }

                BigDecimal dazhuanB = new BigDecimal(dazhuan);
                BigDecimal dazhuanBai = dazhuanB.divide(juminquB,4,BigDecimal.ROUND_HALF_UP); //大专比例
                rMap.put("num10", df.format(dazhuanBai));

                BigDecimal quanrizhiB = new BigDecimal(quanrizhi);
                BigDecimal quanruzhiBai = quanrizhiB.divide(juminquB,2,BigDecimal.ROUND_HALF_UP); //全日制比例
                rMap.put("num12", df.format(quanruzhiBai));

                BigDecimal tuixiufanpinB = new BigDecimal(tuixiufanpin);
                BigDecimal tuixiufanpinBai = tuixiufanpinB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP); //退休返聘比例
                rMap.put("num14", df.format(tuixiufanpinBai));
            }
            dataRows.add(rMap);
        }

        //合计
        rMap = new HashMap<String, Object>();
        rMap.put("street", "合计（以拟参选数为基数）");
        rMap.put("num01", num01c);
        rMap.put("num02", num02c);
        rMap.put("num03", num03c);
        rMap.put("num04", num04c);
        rMap.put("num05", num03c==0?"0%":df.format(new BigDecimal(num04c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        rMap.put("num06", num06c);
        rMap.put("num07", num03c==0?"0%":df.format(new BigDecimal(num06c).divide(new BigDecimal(num03c), 4, BigDecimal.ROUND_UP)));
        rMap.put("num08", num03c == 0 ? "0" : new BigDecimal(age).divide(new BigDecimal(num03c), 2, BigDecimal.ROUND_UP));
        rMap.put("num09", num09c);
        rMap.put("num10", num03c==0?"0%":df.format(new BigDecimal(num09c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        rMap.put("num11", num11c);
        rMap.put("num12", num03c==0?"0%":df.format(new BigDecimal(num11c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        rMap.put("num13", num13c);
        rMap.put("num14", num03c==0?"0%":df.format(new BigDecimal(num13c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));

        dataRows.add(rMap);
        data.put("data",dataRows);
        return ajaxJson(data);
    }

    /**
     * 统计总汇（书记）（换届前后对比）
     */
    @RequestMapping(value = "sjSummaryCompare", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object sjSummaryCompare(){
        DecimalFormat df = new DecimalFormat("0.00%");

        DictItem generalBeforeDict = getGeneralBefore();
        DictItem generalAfterDict = getGeneralAfter();
        String generalBedoreValue = generalBeforeDict!=null?generalBeforeDict.getValue():"";
        String generalAfterValue = generalAfterDict!=null?generalAfterDict.getValue():"";

        Map<String, Object> data = new HashMap<String, Object>();
        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;

        int num01c = 0;
        int num02c = 0;
        int num03c = 0;
        int num04c = 0;
        int num05c = 0;
        int num07c = 0;
        int num09c = 0;
        int num11c = 0;
        int num15c = 0;
        int num17c = 0;
        int num19c = 0;
        int num21c = 0;
        int num23c = 0;
        int num25c = 0;
        int ageBefore = 0;
        int ageAfter = 0;

        User user = userService.getAll().get(0);

        List<DictItem> streetList = getDictItems(user, "street");
        int i=0;
        for(DictItem street:streetList){
            i++;
            int residentCount = personService.getResidentCountByStreet(street); //居民区党组织数

            Map<String, Object> params = new HashMap<String, Object>();
            params.put("street", street);
            params.put("state", BaseEnum.StateEnum.Enable);
            List<Person> personList = personService.getList(params);

            int juminqu0 = 0; //总人数
            int yijiantiao0 = 0; //一肩挑人数
            int nvxing0 = 0; //女性人数
            int allAge0 = 0; //年龄之和
            int dazhuan0 = 0; //大专以上学历人数
            int quanrizhi0 = 0; //全日制人数
            int tuixiufanpin0 = 0; //退休返聘人数

            int juminqu1 = 0; //总人数
            int yijiantiao1 = 0; //一肩挑人数
            int nvxing1 = 0; //女性人数
            int allAge1 = 0; //年龄之和
            int dazhuan1 = 0; //大专以上学历人数
            int quanrizhi1 = 0; //全日制人数
            int tuixiufanpin1 = 0; //退休返聘人数

            for(Person person:personList){
                String thisPersonNature = person.getPersonNature()!=null?person.getPersonNature().getValue():"";
                //换届前
                if(person.getPersonNature()!=null && !"shujihoubei".equals(thisPersonNature) && person.getGeneralDict()!=null && generalBedoreValue.equals(person.getGeneralDict().getValue())){
                    juminqu0++;
                    if(person.getShoulder()==1){
                        if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("已一肩挑")){
                            yijiantiao0++; //一肩挑人数
                        }
                    }

                    if("女".equals(person.getGender())){ //女性人数
                        nvxing0++;
                    }

                    allAge0+=getSummaryAge(person.getBirthday());
                    ageBefore+=getSummaryAge(person.getBirthday());

                    String thisEdu = person.getHighEdu()!=null?person.getHighEdu().getValue():""; //大专以上人数
                    if("edu4".equals(thisEdu) || "edu5".equals(thisEdu) || "edu6".equals(thisEdu)){
                        dazhuan0++;
                        String allDayText = person.getAllDayEdu()!=null?person.getAllDayEdu().getValue():"";
                        if(allDayText.equals(thisEdu)){ //其中全日制人数
                            quanrizhi0++;
                        }
                    }

                    if("tuixiufanpin".equals(thisPersonNature)){ //退休返聘人数
                        tuixiufanpin0++;
                    }
                }


                // -------------------------------------------------------------------------------------------


                //换届后
                if(person.getPersonNature()!=null && !"shujihoubei".equals(thisPersonNature) && person.getGeneralDict()!=null && generalAfterValue.equals(person.getGeneralDict().getValue())){
                    juminqu1++;
                    if(person.getShoulder()==1){
                        if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("已一肩挑")){
                            yijiantiao1++; //一肩挑人数
                        }
                    }

                    if("女".equals(person.getGender())){ //女性人数
                        nvxing1++;
                    }

                    allAge1+=getSummaryAge(person.getBirthday());
                    ageAfter+=getSummaryAge(person.getBirthday());

                    String thisEdu = person.getHighEdu()!=null?person.getHighEdu().getValue():""; //大专以上人数
                    if("edu4".equals(thisEdu) || "edu5".equals(thisEdu) || "edu6".equals(thisEdu)){
                        dazhuan1++;
                        String allDayText = person.getAllDayEdu()!=null?person.getAllDayEdu().getValue():"";
                        if(allDayText.equals(thisEdu)){ //其中全日制人数
                            quanrizhi1++;
                        }
                    }

                    if("tuixiufanpin".equals(thisPersonNature)){ //退休返聘人数
                        tuixiufanpin1++;
                    }
                }

            }

            rMap = new HashMap<String, Object>();
            rMap.put("id", i); //序号
            rMap.put("street", street.getName()); //街道（镇）
            rMap.put("num01", residentCount); //居民区党组织数
            num01c+=residentCount;

            rMap.put("num02", street.getDescription()); //拟参加换届选举
            num02c+=Integer.parseInt(street.getDescription());

            rMap.put("num03", juminqu0); //实有人数
            rMap.put("num04", juminqu1); //实有人数
            num03c+=juminqu0;
            num04c+=juminqu1;

            rMap.put("num05", yijiantiao0); //一肩挑人数
            rMap.put("num07", yijiantiao1); //一肩挑人数
            num05c+=yijiantiao0;
            num07c+=yijiantiao1;

            rMap.put("num09", nvxing0); //女性
            rMap.put("num11", nvxing1); //女性
            num09c+=nvxing0;
            num11c+=nvxing1;

            rMap.put("num15", dazhuan0); //大专以上
            rMap.put("num17", dazhuan1); //大专以上
            num15c+=dazhuan0;
            num17c+=dazhuan1;

            rMap.put("num19", quanrizhi0); //全日制
            rMap.put("num21", quanrizhi1); //全日制
            num19c+=quanrizhi0;
            num21c+=quanrizhi1;

            rMap.put("num23", tuixiufanpin0); //退休返聘
            rMap.put("num25", tuixiufanpin1); //退休返聘
            num23c+=tuixiufanpin0;
            num25c+=tuixiufanpin1;

            if(juminqu0==0){
                rMap.put("num06", "0%");
                rMap.put("num10", "0%");
                rMap.put("num13", "0");
                rMap.put("num16", "0%");
                rMap.put("num20", "0%");
                rMap.put("num24", "0%");
            }else{
                BigDecimal juminquB = new BigDecimal(juminqu0);

                BigDecimal yijiaotiaoB = new BigDecimal(yijiantiao0);
                BigDecimal yijiantiaoBai = yijiaotiaoB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP);
                rMap.put("num06", df.format(yijiantiaoBai)); //一肩挑比例

                BigDecimal nvxingB = new BigDecimal(nvxing0);
                BigDecimal bai = nvxingB.divide(juminquB,4,BigDecimal.ROUND_HALF_UP); //女性比例
                rMap.put("num10", df.format(bai));

                if(allAge0==0){
                    rMap.put("num13", "0");
                }else{
                    BigDecimal allAgeB = new BigDecimal(allAge0);
                    BigDecimal ageAvg = allAgeB.divide(juminquB,2,BigDecimal.ROUND_HALF_UP); //平均年龄
                    rMap.put("num13", ageAvg);
                }

                BigDecimal dazhuanB = new BigDecimal(dazhuan0);
                BigDecimal dazhuanBai = dazhuanB.divide(juminquB,4,BigDecimal.ROUND_HALF_UP); //大专比例
                rMap.put("num16", df.format(dazhuanBai));

                BigDecimal quanrizhiB = new BigDecimal(quanrizhi0);
                BigDecimal quanruzhiBai = quanrizhiB.divide(juminquB,2,BigDecimal.ROUND_HALF_UP); //全日制比例
                rMap.put("num20", df.format(quanruzhiBai));

                BigDecimal tuixiufanpinB = new BigDecimal(tuixiufanpin0);
                BigDecimal tuixiufanpinBai = tuixiufanpinB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP); //退休返聘比例
                rMap.put("num24", df.format(tuixiufanpinBai));
            }

            // ----------------------------------------------------------------------------------------------------------------------

            if(juminqu0==1){
                rMap.put("num08", "0%");
                rMap.put("num12", "0%");
                rMap.put("num14", "0");
                rMap.put("num18", "0%");
                rMap.put("num22", "0%");
                rMap.put("num26", "0%");
            }else{
                BigDecimal juminquB = new BigDecimal(juminqu1);

                BigDecimal yijiaotiaoB = new BigDecimal(yijiantiao1);
                BigDecimal yijiantiaoBai = yijiaotiaoB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP);
                rMap.put("num08", df.format(yijiantiaoBai)); //一肩挑比例

                BigDecimal nvxingB = new BigDecimal(nvxing1);
                BigDecimal bai = nvxingB.divide(juminquB,4,BigDecimal.ROUND_HALF_UP); //女性比例
                rMap.put("num12", df.format(bai));

                if(allAge0==0){
                    rMap.put("num14", "0");
                }else{
                    BigDecimal allAgeB = new BigDecimal(allAge1);
                    BigDecimal ageAvg = allAgeB.divide(juminquB,2,BigDecimal.ROUND_HALF_UP); //平均年龄
                    rMap.put("num14", ageAvg);
                }

                BigDecimal dazhuanB = new BigDecimal(dazhuan1);
                BigDecimal dazhuanBai = dazhuanB.divide(juminquB,4,BigDecimal.ROUND_HALF_UP); //大专比例
                rMap.put("num18", df.format(dazhuanBai));

                BigDecimal quanrizhiB = new BigDecimal(quanrizhi1);
                BigDecimal quanruzhiBai = quanrizhiB.divide(juminquB,2,BigDecimal.ROUND_HALF_UP); //全日制比例
                rMap.put("num22", df.format(quanruzhiBai));

                BigDecimal tuixiufanpinB = new BigDecimal(tuixiufanpin1);
                BigDecimal tuixiufanpinBai = tuixiufanpinB.divide(juminquB, 4, BigDecimal.ROUND_HALF_UP); //退休返聘比例
                rMap.put("num26", df.format(tuixiufanpinBai));
            }

            dataRows.add(rMap);
        }

        //合计
        rMap = new HashMap<String, Object>();
        rMap.put("street", "合计（以拟参选数为基数）");
        rMap.put("num01", num01c);
        rMap.put("num02", num02c);
        rMap.put("num03", num03c);
        rMap.put("num04", num04c);
        BigDecimal beforeNum = new BigDecimal(num03c); //换届前总人数
        BigDecimal afterNum = new BigDecimal(num04c); //换届后总人数
        rMap.put("num05", num05c);
        rMap.put("num06", num03c==0?"0%":df.format(new BigDecimal(num05c).divide(beforeNum,4,BigDecimal.ROUND_UP)));
        rMap.put("num07", num07c);
        rMap.put("num08", num04c==0?"0%":df.format(new BigDecimal(num07c).divide(afterNum,4,BigDecimal.ROUND_UP)));
        rMap.put("num09", num09c);
        rMap.put("num10", num03c==0?"0%":df.format(new BigDecimal(num09c).divide(beforeNum,4,BigDecimal.ROUND_UP)));
        rMap.put("num11", num11c);
        rMap.put("num12", num04c==0?"0%":df.format(new BigDecimal(num11c).divide(afterNum,4,BigDecimal.ROUND_UP)));
        rMap.put("num13", num03c == 0 ? "0" : new BigDecimal(ageBefore).divide(beforeNum, 2, BigDecimal.ROUND_UP));
        rMap.put("num14", num04c == 0 ? "0" : new BigDecimal(ageAfter).divide(afterNum, 2, BigDecimal.ROUND_UP));
        rMap.put("num15", num15c);
        rMap.put("num16", num03c==0?"0%":df.format(new BigDecimal(num15c).divide(beforeNum,4,BigDecimal.ROUND_UP)));
        rMap.put("num17", num17c);
        rMap.put("num18", num04c==0?"0%":df.format(new BigDecimal(num17c).divide(afterNum, 4, BigDecimal.ROUND_UP)));
        rMap.put("num19", num19c);
        rMap.put("num20", num03c==0?"0%":df.format(new BigDecimal(num19c).divide(beforeNum,4,BigDecimal.ROUND_UP)));
        rMap.put("num21", num21c);
        rMap.put("num22", num04c==0?"0%":df.format(new BigDecimal(num21c).divide(afterNum,4,BigDecimal.ROUND_UP)));
        rMap.put("num23", num23c);
        rMap.put("num24", num03c==0?"0%":df.format(new BigDecimal(num23c).divide(beforeNum,4,BigDecimal.ROUND_UP)));
        rMap.put("num25", num25c);
        rMap.put("num26", num04c==0?"0%":df.format(new BigDecimal(num25c).divide(afterNum,4,BigDecimal.ROUND_UP)));

        dataRows.add(rMap);
        data.put("data",dataRows);
        return ajaxJson(data);
    }



    /**
     * 统计总汇（主任）
     */
    @RequestMapping(value = "zrSummary", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object zrSummary(){
        DecimalFormat df = new DecimalFormat("0.00%");

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> data = new HashMap<String, Object>();
        Map<String, Object> rMap;

        User user = userService.getAll().get(0);
        List<DictItem> streetList = getDictItems(user, "street");

        int num01c = 0;
        int num02c = 0;
        int num03c = 0;
        int num04c = 0;
        int num05c = 0;
        int num06c = 0;
        int num09c = 0;
        int num11c = 0;
        int num13c = 0;
        int num15c = 0;
        int num17c = 0;
        int num19c = 0;
        int age = 0;

        int i=0;
        for(DictItem street:streetList){
            i++;

            Map<String, Object> params = new HashMap<String, Object>();
            params.put("street", street);
            params.put("state", BaseEnum.StateEnum.Enable);
            params.put("company", user.getCompany());
            List<Director> directorList = directorService.getList(params); //此街道上的所有人

            rMap = new HashMap<String, Object>();
            int residentCount = personService.getResidentCountByStreet(street);
            rMap.put("num02", street.getDescription()); //居委会数
            num02c+=residentCount;

            int directorCount = directorList.size();
            rMap.put("id", i); //序号
            rMap.put("num03", directorCount);//实有人数
            num03c+=directorCount;

            rMap.put("street", street.getName()); //街道
//            rMap.put("streetId", street.getId()); //街道id
            rMap.put("num01", residentCount); //固定数量
            num01c+=Integer.parseInt(street.getDescription());

            int yijiantiao = 0; //一肩挑人数
            int niyijiantiao = 0; //拟一肩挑人数
            int nvxing = 0; //女性人数
            int ageCount = 0; //年龄之和
            int jiuye = 0; //就业年龄段人数
            int dazhuan = 0; //大专以上人数
            int quanrizhi = 0; //全日制人数
            int dangyuan = 0; //中共党员人数（有入党时间的话就是党员）
            int dangyuannan = 0; //党员 男
            int dangyuannv = 0; //党员 女

            for(Director director:directorList){

                ageCount+=getSummaryAge(director.getBirthday());
                age+=ageCount;

                if(director.getShoulder()==1){
                    if(director.getShoulderDet().contains("已一肩挑")){
                        yijiantiao++;
                    }
                    if(director.getShoulderDet().contains("拟一肩挑备选")){
                        niyijiantiao++;
                    }
                }

                if("女".equals(director.getGender())){
                    nvxing++;
                    if(getSummaryAge(director.getBirthday())<50){
                        jiuye++;
                    }
                }else{
                    if(getSummaryAge(director.getBirthday())<60){
                        jiuye++;
                    }
                }

                String thisEdu = director.getHighEdu()!=null?director.getHighEdu().getValue():""; //大专以上人数
                if("edu4".equals(thisEdu) || "edu5".equals(thisEdu) || "edu6".equals(thisEdu)){
                    dazhuan++;
                }

                if(director.getAllDayEdu()!=null){ //其中：全日制人数
                    quanrizhi++;
                }

                if(director.getJoinPartyDate()!=null){
                    dangyuan++;
                    if("男".equals(director.getGender())){
                        if(getSummaryAge(director.getBirthday())<57){
                            dangyuannan++;
                        }
                    }else{
                        if(getSummaryAge(director.getBirthday())<52){
                            dangyuannv++;
                        }
                    }
                }
            }

            rMap.put("num04", yijiantiao); //一肩挑人数
            num04c+=yijiantiao;

            rMap.put("num05", niyijiantiao); //拟一肩挑人数
            num05c+=niyijiantiao;

            rMap.put("num06", nvxing); //女性人数
            num06c+=nvxing;

            rMap.put("num09", jiuye); //就业年龄段人数
            num09c+=jiuye;

            rMap.put("num11", dazhuan); //大专以上人数
            num11c+=dazhuan;

            rMap.put("num13", quanrizhi); //全日制人数
            num13c+=quanrizhi;

            rMap.put("num15", dangyuan); //中共党员人数
            num15c+=dangyuan;

            rMap.put("num17", dangyuannan); //党员男
            num17c+=dangyuannan;

            rMap.put("num19", dangyuannv); //党员女
            num19c+=dangyuannv;

            if(directorCount==0){
                rMap.put("num08", 0);
                rMap.put("num10", "0%");
                rMap.put("num12", "0%");
                rMap.put("num14", "0%");
                rMap.put("num07", "0%");
                rMap.put("num16", "0%");
            }else{
                BigDecimal all = new BigDecimal(directorCount);
                rMap.put("num07", df.format(new BigDecimal(nvxing).divide(all,4,BigDecimal.ROUND_UP))); //女性比例
                rMap.put("num08", new BigDecimal(ageCount).divide(all, 2, BigDecimal.ROUND_UP)); //平均年龄
                rMap.put("num10", df.format(new BigDecimal(jiuye).divide(all, 4, BigDecimal.ROUND_UP))); //就业年龄段人数
                rMap.put("num12", df.format(new BigDecimal(dazhuan).divide(all,4,BigDecimal.ROUND_UP))); //大专比例
                rMap.put("num14", df.format(new BigDecimal(quanrizhi).divide(all,4,BigDecimal.ROUND_UP))); //全日制比例
                rMap.put("num16", df.format(new BigDecimal(dangyuan).divide(all,4,BigDecimal.ROUND_UP))); //中共党员比例
            }

            //党员比例
            if(dangyuan==0){
                rMap.put("num18", "0%");
                rMap.put("num20", "0%");
            }else{
                BigDecimal dangyuanAll = new BigDecimal(dangyuan);
                rMap.put("num18", df.format(new BigDecimal(dangyuannan).divide(dangyuanAll,4,BigDecimal.ROUND_UP))); //党员男比例
                rMap.put("num20", df.format(new BigDecimal(dangyuannv).divide(dangyuanAll,4,BigDecimal.ROUND_UP))); //党员女比例
            }

            dataRows.add(rMap);
        }

        //合计
        rMap = new HashMap<String, Object>();
        rMap.put("street", "合计");
        rMap.put("num01", num01c);
        rMap.put("num02", num02c);
        rMap.put("num03", num03c);
        rMap.put("num04", num04c);
        rMap.put("num05", num05c);
        rMap.put("num06", num06c);
        rMap.put("num07", num03c==0?"0%":df.format(new BigDecimal(num06c).divide(new BigDecimal(num03c), 4, BigDecimal.ROUND_UP)));
        rMap.put("num08", num03c==0?"0":new BigDecimal(age).divide(new BigDecimal(num03c), 2, BigDecimal.ROUND_UP));
        rMap.put("num09", num09c);
        rMap.put("num10", num03c==0?"0%":df.format(new BigDecimal(num09c).divide(new BigDecimal(num03c), 4, BigDecimal.ROUND_UP)));
        rMap.put("num11", num11c);
        rMap.put("num12", num03c==0?"0%":df.format(new BigDecimal(num11c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        rMap.put("num13", num13c);
        rMap.put("num14", num03c==0?"0%":df.format(new BigDecimal(num13c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        rMap.put("num15", num15c);
        rMap.put("num16", num03c==0?"0%":df.format(new BigDecimal(num15c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        rMap.put("num17", num17c);
        rMap.put("num18", num03c==0?"0%":df.format(new BigDecimal(num17c).divide(new BigDecimal(num03c),4,BigDecimal.ROUND_UP)));
        rMap.put("num19", num19c);
        rMap.put("num20", num03c == 0 ? "0%" : df.format(new BigDecimal(num19c).divide(new BigDecimal(num03c), 4, BigDecimal.ROUND_UP)));
        dataRows.add(rMap);

        data.put("data", dataRows);
        return ajaxJson(data);
    }

    /**
     * 根据街道获得所有书记的信息
     * @param streetNo 街道序号0-11
     * @return
     */
    @RequestMapping(value = "sjList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object sjList(Integer streetNo, String type){

        String ip = "";
        String port = "";

        try {
            InetAddress inet = InetAddress.getLocalHost();
            ip = inet.getHostAddress();
            port = String.valueOf(request.getLocalPort());
        } catch (UnknownHostException e) {
            e.printStackTrace();
//            ip = "10.10.11.39";
//            port = "8082";
            System.out.println("=== 没有自动获取到地址 ===");
        }

        if(streetNo==null){
            return ajaxText("streetNo为空");
        }

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("value", "street"+streetNo);
        List<DictItem> dictItemList = dictItemService.getList(params);
        List<Person> personList = new ArrayList<Person>();
        String streetName = "";
        if(dictItemList.size()>0){
            streetName = dictItemList.get(0).getName();
            Map<String, Object> personParams = new HashMap<String, Object>();
            personParams.put("street", dictItemList.get(0));
            personParams.put("state", BaseEnum.StateEnum.Enable);

            if(StringUtils.isEmpty(type) || "after".equals(type)){
                personParams.put("generalDict", getGeneralAfter());
            }else{
                personParams.put("generalDict", getGeneralBefore());
            }

            personList = personService.getList(personParams);
        }

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> data = new HashMap<String, Object>();
        Map<String, Object> rMap;
        for(Person person:personList){

            if(person.getPersonNature()==null){
                continue;
            }

            rMap = new HashMap<String, Object>();
            rMap.put("NotesID", StringUtils.isNotEmpty(person.getId())?person.getId():"");
            rMap.put("UNID", StringUtils.isNotEmpty(person.getId())?person.getId():"");
            rMap.put("txtName", StringUtils.isNotEmpty(person.getName())?person.getName():"");
            rMap.put("txtSex", StringUtils.isNotEmpty(person.getGender())?person.getGender():"");
            rMap.put("datBorn", person.getBirthday()!=null?DataUtil.DateToString(person.getBirthday(), "yyyy年MM月"):"");
            rMap.put("txtNation", person.getNation()!=null?person.getNation().getName():"");
            rMap.put("txtNative", StringUtils.isNotEmpty(person.getOrigin())?person.getOrigin():"");
            rMap.put("txtBorn", StringUtils.isNotEmpty(person.getBirthPlace())?person.getBirthPlace():"");
            rMap.put("txtHealth", StringUtils.isNotEmpty(person.getHealth())?person.getHealth():"");
            rMap.put("datRD", person.getJoinPartyDate()!=null?DataUtil.DateToString(person.getJoinPartyDate(), "yyyy年MM月"):"");
            rMap.put("datWork", person.getJoinWorkDate()!=null?DataUtil.DateToString(person.getJoinWorkDate(), "yyyy年MM月"):"");
            rMap.put("txtTecDuty", StringUtils.isNotEmpty(person.getTxtTecDuty())?person.getTxtTecDuty():"");
            rMap.put("txtSpec", StringUtils.isNotEmpty(person.getSpecialty())?person.getSpecialty():"");
            rMap.put("txtWorkType", person.getWorkNature()!=null?person.getWorkNature().getName():"");
            rMap.put("txtEducation", person.getHighEdu()!=null?person.getHighEdu().getName():"");
            rMap.put("txtEducation_1", person.getAllDayEdu()!=null?person.getAllDayEdu().getName():"");
            rMap.put("txtEducation_2", person.getJobEdu()!=null?person.getJobEdu().getName():"");
            rMap.put("txtSpec_1", StringUtils.isNotEmpty(person.getAllDaySchool())?person.getAllDaySchool():"");
            rMap.put("txtSpec_2", StringUtils.isNotEmpty(person.getJobSchool())?person.getJobSchool():"");
            rMap.put("txtDuty", StringUtils.isNotEmpty(person.getNowPost())?person.getNowPost():"");
            rMap.put("datStart", person.getNowPostDate()!=null?DataUtil.DateToString(person.getNowPostDate(), "yyyy年MM月"):"");
            rMap.put("txtArea", StringUtils.isNotEmpty(person.getArea())?person.getArea():"");
            rMap.put("txtStreet", person.getStreet()!=null?person.getStreet().getName():"");
            rMap.put("txtType", person.getPersonNature()!=null?person.getPersonNature().getName():"");
            rMap.put("txtJWH", person.getResident()!=null?person.getResident().getName():"");
            rMap.put("txtYJT", person.getShoulder()==1?"是":"否");
            rMap.put("txtYJTs", StringUtils.isNotEmpty(person.getShoulderDet())?person.getShoulderDet():"");
            rMap.put("numAge", person.getBirthday()!=null?getAge(person.getBirthday()):"0");
            rMap.put("datApprove", person.getCreateTime()!=null?DataUtil.DateToString(person.getCreateTime(), "yyyy年MM月dd日"):"");
            rMap.put("cardId", StringUtils.isNotEmpty(person.getCardId())?person.getCardId():"");

            List<Study> studyList = person.getStudyList();
            for(int i=0;i<studyList.size();i++){
                Study study = studyList.get(i);
                rMap.put("datStart_"+(i+1),study.getStartDate()!=null?DataUtil.DateToString(study.getStartDate(),"yyyy年MM月"):"");
                rMap.put("datEnd_"+(i+1),study.getEndDate()!=null?DataUtil.DateToString(study.getEndDate(),"yyyy年MM月"):"");
                rMap.put("txtSchool_"+(i+1), StringUtils.isNotEmpty(study.getSchool())?study.getSchool():"");
                rMap.put("txtStu_"+(i+1), StringUtils.isNotEmpty(study.getAcademicDegree())?study.getAcademicDegree():"");
            }

            List<Work> workList = person.getWorkList();
            for(int i=0;i<workList.size();i++){
                Work work = workList.get(i);
                rMap.put("datWStart_"+(i+1), work.getWorkStartDate()!=null?DataUtil.DateToString(work.getWorkStartDate(), "yyyy年MM月"):"");
                rMap.put("datWEnd_"+(i+1), work.getWorkEndDate()!=null?DataUtil.DateToString(work.getWorkEndDate(), "yyyy年MM月"):"");
                rMap.put("txtUnit_"+(i+1), StringUtils.isNotEmpty(work.getWorkDept())?work.getWorkDept():"");
                rMap.put("txtDuty_"+(i+1), StringUtils.isNotEmpty(work.getWorkPost())?work.getWorkPost():"");
                rMap.put("txtZMR_"+(i+1), StringUtils.isNotEmpty(work.getProveUser())?work.getProveUser():"");
            }

            rMap.put("txtInfo", StringUtils.isNotEmpty(person.getReward())?person.getReward():"");

            List<Family> familyList = person.getFamilyList();
            for(int i=0;i<familyList.size();i++){
                Family family = familyList.get(i);
                rMap.put("txtCW_"+(i+1), StringUtils.isNotEmpty(family.getNickName())?family.getNickName():"");
                rMap.put("txtName_"+(i+1), StringUtils.isNotEmpty(family.getFamilyName())?family.getFamilyName():"");
                rMap.put("datBorn_"+(i+1), family.getFamilyBirthday()!=null?DataUtil.DateToString(family.getFamilyBirthday(), "yyyy年MM日"):"");
                rMap.put("txtZZ_"+(i+1), StringUtils.isNotEmpty(family.getPoliticalStatus())?family.getPoliticalStatus():"");
                rMap.put("txtXL_"+(i+1), StringUtils.isNotEmpty(family.getFamilyEdu())?family.getFamilyEdu():"");
                rMap.put("txtUD_"+(i+1), StringUtils.isNotEmpty(family.getFamilyJob())?family.getFamilyJob():"");
            }
            rMap.put("txtFamilyAddress", StringUtils.isNotEmpty(person.getFamilyAddress())?person.getFamilyAddress():"");
            rMap.put("txtPhone", StringUtils.isNotEmpty(person.getPhone())?person.getPhone():"");
            rMap.put("txtFileName", person.getPhoto()!=null?"http://"+ip+":"+port+"/jj-web/common/file/download?"+person.getPhoto().getUrl():"");
            rMap.put("txtPostCode", StringUtils.isNotEmpty(person.getZipCode())?person.getZipCode():"");
            dataRows.add(rMap);
        }
        data.put("street",StringUtils.isNotEmpty(streetName)?streetName:"");
        data.put("persons", dataRows);

        return ajaxJson(data);
    }

    /**
     * 根据街道获得所有主任的信息
     * @param streetNo 街道序号0-11
     * @return
     */
    @RequestMapping(value = "zrList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object zrList(Integer streetNo){
        System.out.println("请求 获取主任信息 streetNo:"+streetNo);
        String ip = "";
        String port = "";

        try {
            InetAddress inet = InetAddress.getLocalHost();
            ip = inet.getHostAddress();
            port = String.valueOf(request.getLocalPort());
        } catch (UnknownHostException e) {
            e.printStackTrace();
//            ip = "10.10.11.39";
//            port = "8082";
            System.out.println("=== 没有自动获取到地址 ===");
        }

        if(streetNo==null){
            return ajaxText("streetNo为空");
        }

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("value", "street"+streetNo);
        List<DictItem> dictItemList = dictItemService.getList(params);
        List<Director> directorList = new ArrayList<Director>();
        String streetName = "";
        if(dictItemList.size()>0){
            streetName = dictItemList.get(0).getName();
            Map<String, Object> directorParams = new HashMap<String, Object>();
            directorParams.put("street", dictItemList.get(0));
            directorParams.put("state", BaseEnum.StateEnum.Enable);
            directorList = directorService.getList(directorParams);
        }

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> data = new HashMap<String, Object>();
        Map<String, Object> rMap;
        for(Director person:directorList){
            rMap = new HashMap<String, Object>();
            rMap.put("NotesID", StringUtils.isNotEmpty(person.getId())?person.getId():"");
            rMap.put("UNID", StringUtils.isNotEmpty(person.getId())?person.getId():"");
            rMap.put("txtName", StringUtils.isNotEmpty(person.getName())?person.getName():"");
            rMap.put("txtSex", StringUtils.isNotEmpty(person.getGender())?person.getGender():"");
            rMap.put("datBorn", person.getBirthday()!=null?DataUtil.DateToString(person.getBirthday(), "yyyy年MM月"):"");
            rMap.put("txtNation", person.getNation()!=null?person.getNation().getName():"");
            rMap.put("txtNative", StringUtils.isNotEmpty(person.getOrigin())?person.getOrigin():"");
            rMap.put("txtBorn", StringUtils.isNotEmpty(person.getBirthPlace())?person.getBirthPlace():"");
            rMap.put("txtHealth", StringUtils.isNotEmpty(person.getHealth())?person.getHealth():"");
            rMap.put("datRD", person.getJoinPartyDate()!=null?DataUtil.DateToString(person.getJoinPartyDate(), "yyyy年MM月"):"");
            rMap.put("datWork", person.getJoinWorkDate()!=null?DataUtil.DateToString(person.getJoinWorkDate(), "yyyy年MM月"):"");
            rMap.put("txtTecDuty", StringUtils.isNotEmpty(person.getTxtTecDuty())?person.getTxtTecDuty():"");
            rMap.put("txtSpec", StringUtils.isNotEmpty(person.getSpecialty())?person.getSpecialty():"");
            rMap.put("txtWorkType", person.getWorkNature()!=null?person.getWorkNature().getName():"");
            rMap.put("txtType", person.getPersonNature()!=null?person.getPersonNature().getName():"");
            rMap.put("txtEducation", person.getHighEdu()!=null?person.getHighEdu().getName():"");
            rMap.put("txtEducation_1", person.getAllDayEdu()!=null?person.getAllDayEdu().getName():"");
            rMap.put("txtEducation_2", person.getJobEdu()!=null?person.getJobEdu().getName():"");
            rMap.put("txtSpec_1", StringUtils.isNotEmpty(person.getAllDaySchool())?person.getAllDaySchool():"");
            rMap.put("txtSpec_2", StringUtils.isNotEmpty(person.getJobSchool())?person.getJobSchool():"");
            rMap.put("txtDuty", StringUtils.isNotEmpty(person.getNowPost())?person.getNowPost():"");
            rMap.put("datStart", person.getNowPostDate()!=null?DataUtil.DateToString(person.getNowPostDate(), "yyyy年MM月"):"");
            rMap.put("txtArea", StringUtils.isNotEmpty(person.getArea())?person.getArea():"");
            rMap.put("txtStreet", person.getStreet()!=null?person.getStreet().getName():"");
            rMap.put("txtJWH", person.getResident()!=null?person.getResident().getName():"");
            rMap.put("txtYJT", person.getShoulder()==1?"是":"否");
            rMap.put("txtYJTs", StringUtils.isNotEmpty(person.getShoulderDet())?person.getShoulderDet():"");
            rMap.put("numAge", person.getBirthday()!=null?getAge(person.getBirthday()):"0");
            rMap.put("datApprove", person.getCreateTime()!=null?DataUtil.DateToString(person.getCreateTime(), "yyyy年MM月dd日"):"");
            rMap.put("txtZZMM", StringUtils.isNotEmpty(person.getZzmm())?person.getZzmm():"");
            rMap.put("cardId", StringUtils.isNotEmpty(person.getCardId())?person.getCardId():"");

            List<Study> studyList = person.getStudyList();
            for(int i=0;i<studyList.size();i++){
                Study study = studyList.get(i);
                rMap.put("datStart_"+(i+1),study.getStartDate()!=null?DataUtil.DateToString(study.getStartDate(),"yyyy年MM月"):"");
                rMap.put("datEnd_"+(i+1),study.getEndDate()!=null?DataUtil.DateToString(study.getEndDate(),"yyyy年MM月"):"");
                rMap.put("txtSchool_"+(i+1), StringUtils.isNotEmpty(study.getSchool())?study.getSchool():"");
                rMap.put("txtStu_"+(i+1), StringUtils.isNotEmpty(study.getAcademicDegree())?study.getAcademicDegree():"");
            }

            List<Work> workList = person.getWorkList();
            for(int i=0;i<workList.size();i++){
                Work work = workList.get(i);
                rMap.put("datWStart_"+(i+1), work.getWorkStartDate()!=null?DataUtil.DateToString(work.getWorkStartDate(), "yyyy年MM月"):"");
                rMap.put("datWEnd_"+(i+1), work.getWorkEndDate()!=null?DataUtil.DateToString(work.getWorkEndDate(), "yyyy年MM月"):"");
                rMap.put("txtUnit_"+(i+1), StringUtils.isNotEmpty(work.getWorkDept())?work.getWorkDept():"");
                rMap.put("txtDuty_"+(i+1), StringUtils.isNotEmpty(work.getWorkPost())?work.getWorkPost():"");
                rMap.put("txtZMR_"+(i+1), StringUtils.isNotEmpty(work.getProveUser())?work.getProveUser():"");
            }

            rMap.put("txtInfo", StringUtils.isNotEmpty(person.getReward())?person.getReward():"");

            List<Family> familyList = person.getFamilyList();
            for(int i=0;i<familyList.size();i++){
                Family family = familyList.get(i);
                rMap.put("txtCW_"+(i+1), StringUtils.isNotEmpty(family.getNickName())?family.getNickName():"");
                rMap.put("txtName_"+(i+1), StringUtils.isNotEmpty(family.getFamilyName())?family.getFamilyName():"");
                rMap.put("datBorn_"+(i+1), family.getFamilyBirthday()!=null?DataUtil.DateToString(family.getFamilyBirthday(), "yyyy年MM日"):"");
                rMap.put("txtZZ_"+(i+1), StringUtils.isNotEmpty(family.getPoliticalStatus())?family.getPoliticalStatus():"");
                rMap.put("txtXL_"+(i+1), StringUtils.isNotEmpty(family.getFamilyEdu())?family.getFamilyEdu():"");
                rMap.put("txtUD_"+(i+1), StringUtils.isNotEmpty(family.getFamilyJob())?family.getFamilyJob():"");
            }
            rMap.put("txtFamilyAddress", StringUtils.isNotEmpty(person.getFamilyAddress())?person.getFamilyAddress():"");
            rMap.put("txtPhone", StringUtils.isNotEmpty(person.getPhone())?person.getPhone():"");
            rMap.put("txtFileName", person.getPhoto()!=null?"http://"+ip+":"+port+"/jj-web/common/file/download?"+person.getPhoto().getUrl():"");
            rMap.put("txtPostCode", StringUtils.isNotEmpty(person.getZipCode())?person.getZipCode():"");
            dataRows.add(rMap);
        }
        data.put("street",StringUtils.isNotEmpty(streetName)?streetName:"");
        data.put("persons", dataRows);

        return ajaxJson(data);
    }

    /**
     * 获取一个街道下的居民区
     * @param streetNo
     * @return
     */
    @RequestMapping(value = "getResident", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object getResident(String streetNo){
        System.out.println(streetNo);
        Map<String, Object> data = new HashMap<String, Object>();
        if(streetNo!=null){
            DictItem street = residentService.getStreetByNo(Integer.parseInt(streetNo));
            if(street!=null){
                System.out.println(street.getId());
                List<Resident> residentList = residentService.getResidentByStreet(street);

                List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
                Map<String, Object> rMap;
                int i=0;
                for(Resident resident:residentList){
                    i++;
                    rMap = new HashMap<String, Object>();
                    rMap.put("id", String.valueOf(i));
                    rMap.put("txtStreet", StringUtils.isNotEmpty(resident.getName())?resident.getName():"");
                    dataRows.add(rMap);
                }
                data.put("data", dataRows);
            }
        }

        return ajaxJson(data);
    }

    /**
     * 根据性别分类
     * @param streetNo 街道编号 0-11
     * @param isBx 是否是备选 0居民区书记 1备选书记
     * @return
     */
    @RequestMapping(value = "getGender", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public Object getGender(Integer streetNo, String isBx, String type){
        System.out.println(streetNo);
        if(streetNo==null){
            return ajaxText("streetNo为空");
        }

        DictItem beixuan = beiXuan();
        DictItem street = residentService.getStreetByNo(streetNo);
        Map<String, Object> table = new HashMap<String, Object>();
        if(street!=null){
            List<Rule> rules = new ArrayList<Rule>();
            rules.add(RuleHelper.eq("street", street));
            rules.add(RuleHelper.isNotNull("personNature"));

            if("before".equals(type)){
                rules.add(RuleHelper.eq("generalDict", getGeneralBefore()));
            }else{
                rules.add(RuleHelper.eq("generalDict", getGeneralAfter()));
            }

            if("1".equals(isBx)){
                rules.add(RuleHelper.eq("personNature", beixuan));
            }else{
                rules.add(RuleHelper.ne("personNature", beixuan));
            }

            List<Person> personList = personService.findPerson(rules);

            int i=0;
            int j=0;
            Map<String, Object> data;
            Map<String, Object> rMap;
            List<Map<String, Object>> dataRowsNan = new ArrayList<Map<String, Object>>();
            List<Map<String, Object>> dataRowsNv = new ArrayList<Map<String, Object>>();

            List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
            for(Person person:personList){
                rMap = new HashMap<String, Object>();
                rMap.put("noteid", person.getId());
                rMap.put("numAge", person.getBirthday() != null ? String.valueOf(getAge(person.getBirthday())) : "");
                rMap.put("txtName", StringUtils.isNotEmpty(person.getName())?person.getName():"");
                if("男".equals(person.getGender())){
                    i++;
                    rMap.put("id", String.valueOf(i));
                    dataRowsNan.add(rMap);
                }else{
                    j++;
                    rMap.put("id", String.valueOf(j));
                    dataRowsNv.add(rMap);
                }
            }

            data = new HashMap<String, Object>();
            data.put("data", dataRowsNv);
            data.put("txtType", "女");
            dataRows.add(data);

            data = new HashMap<String, Object>();
            data.put("data", dataRowsNan);
            data.put("txtType", "男");
            dataRows.add(data);

            table.put("table", dataRows);
        }
        return ajaxJson(table);
    }

    /**
     * 根据大专分类
     * @return
     */
    @RequestMapping(value = "getEdu", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object getEdu(Integer streetNo, String isBx, String type){
        if(streetNo==null){
            return ajaxText("streetNo为空");
        }

        DictItem street = residentService.getStreetByNo(streetNo);
        Map<String, Object> table = new HashMap<String, Object>();
        if(street!=null) {
            DictItem beixuan = beiXuan();
            List<Rule> rules = new ArrayList<Rule>();
            rules.add(RuleHelper.eq("street", street));
            rules.add(RuleHelper.isNotNull("personNature"));

            if("before".equals(type)){
                rules.add(RuleHelper.eq("generalDict", getGeneralBefore()));
            }else{
                rules.add(RuleHelper.eq("generalDict", getGeneralAfter()));
            }

            if("1".equals(isBx)){
                rules.add(RuleHelper.eq("personNature", beixuan));
            }else{
                rules.add(RuleHelper.ne("personNature", beixuan));
            }

            List<Person> personList = personService.findPerson(rules);

            int i = 1;
            int j = 1;
            Map<String, Object> data;
            Map<String, Object> rMap;
            List<Map<String, Object>> dataRowsUp = new ArrayList<Map<String, Object>>();
            List<Map<String, Object>> dataRowsDown = new ArrayList<Map<String, Object>>();
            List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();

            for (Person person : personList) {

                rMap = new HashMap<String, Object>();
                rMap.put("noteid", person.getId());
                rMap.put("txtName", StringUtils.isNotEmpty(person.getName()) ? person.getName() : "");
                rMap.put("txtEducation", person.getHighEdu() != null ? person.getHighEdu().getName() : "");
                if (person.getHighEdu() != null) {

                    String eduId = person.getHighEdu().getId();
                    if (eduId.equals(person.getAllDaySchool())) {
                        rMap.put("txtXZ", "全日制教育");
                    } else {
                        rMap.put("txtXZ", "在职教育");
                    }
                }else{

                }
                rMap.put("txtSex", StringUtils.isNotEmpty(person.getGender()) ? person.getGender() : "");
                String eduVal = person.getHighEdu() != null ? person.getHighEdu().getValue() : "";
                if ("edu4".equals(eduVal) || "edu5".equals(eduVal) || "edu6".equals(eduVal)) {
                    rMap.put("id", String.valueOf(i++));
                    dataRowsUp.add(rMap);
                } else {
                    rMap.put("id", String.valueOf(j++));
                    dataRowsDown.add(rMap);
                }
            }

            data = new HashMap<String, Object>();
            data.put("data", dataRowsUp);
            data.put("txtType", "大专及以上学历");
            dataRows.add(data);

            data = new HashMap<String, Object>();
            data.put("data", dataRowsDown);
            data.put("txtType", "大专以下学历");
            dataRows.add(data);

            table.put("table", dataRows);
        }
        return ajaxJson(table);
    }

    /**
     * 根据退休分类 退休返聘
     * @return
     */
    @RequestMapping(value = "getTuixiu", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object getTuixiu(Integer streetNo, String type){
        if(streetNo==null){
            return ajaxText("streetNo为空");
        }

        Map<String, Object> data =new HashMap<String, Object>();
        DictItem street = residentService.getStreetByNo(streetNo);
        if(street!=null) {
            DictItem fanPin = null;
            Dict personNature = dictService.getByValue("personNature");
            if(personNature!=null){
                fanPin = dictItemService.getByValue(personNature.getId(), "tuixiufanpin");
            }

            List<Rule> rules = new ArrayList<Rule>();
            rules.add(RuleHelper.eq("street", street));
            rules.add(RuleHelper.isNotNull("personNature"));
            rules.add(RuleHelper.eq("personNature", fanPin));
            if("before".equals(type)){
                rules.add(RuleHelper.eq("generalDict", getGeneralBefore()));
            }else{
                rules.add(RuleHelper.eq("generalDict", getGeneralAfter()));
            }
            List<Person> personList = personService.findPerson(rules);

            Map<String, Object> rMap;
            List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
            int i=0;
            for (Person person : personList) {
                i++;
                rMap = new HashMap<String, Object>();
                rMap.put("id", String.valueOf(i));
                rMap.put("noteid", person.getId());
                rMap.put("txtName", StringUtils.isNotEmpty(person.getName())?person.getName():"");
                rMap.put("txtEducation", person.getHighEdu()!=null?person.getHighEdu().getName():"");
                rMap.put("txtSex", StringUtils.isNotEmpty(person.getGender())?person.getGender():"");
                rMap.put("numAge", person.getBirthday()!=null?String.valueOf(getAge(person.getBirthday())):"");
                dataRows.add(rMap);
            }
            data.put("data", dataRows);
        }
        return ajaxJson(data);
    }

    /**
     * 根据拟明确为明确备选分类
     * @return
     */
    @RequestMapping(value = "getIsClear", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object getIsClear(Integer streetNo){
        if(streetNo==null){
            return ajaxText("streetNo为空");
        }

        Map<String, Object> data;
        Map<String, Object> table = new HashMap<String, Object>();
        DictItem street = residentService.getStreetByNo(streetNo);
        if(street!=null) {
            List<Rule> rules = new ArrayList<Rule>();
            rules.add(RuleHelper.eq("street", street));
            rules.add(RuleHelper.eq("personNature", beiXuan()));
            rules.add(RuleHelper.eq("generalDict", getGeneralBefore()));
            List<Person> personList = personService.findPerson(rules);

            int i=0;
            int j=0;
            Map<String, Object> rMap;
            List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
            List<Map<String, Object>> dataRowsY = new ArrayList<Map<String, Object>>();
            List<Map<String, Object>> dataRowsN = new ArrayList<Map<String, Object>>();
            for (Person person : personList) {
                if(person.getPersonNature()!=null && "shujihoubei".equals(person.getPersonNature().getValue())){
                    rMap = new HashMap<String, Object>();
                    rMap.put("noteid", person.getId());
                    rMap.put("txtName", StringUtils.isNotEmpty(person.getName())?person.getName():"");
                    rMap.put("txtEducation", person.getHighEdu() != null ? person.getHighEdu().getName() : "");
                    rMap.put("txtSex", StringUtils.isNotEmpty(person.getGender()) ? person.getGender() : "");
                    if(person.getResident()!=null){
                        i++;
                        rMap.put("id", String.valueOf(i));
                        dataRowsY.add(rMap);
                    }else{
                        j++;
                        rMap.put("id", String.valueOf(j));
                        dataRowsN.add(rMap);
                    }
                }
            }
            data = new HashMap<String, Object>();
            data.put("txtType", "拟明确备选居民区");
            data.put("data", dataRowsY);
            dataRows.add(data);

            data = new HashMap<String, Object>();
            data.put("txtType", "未明确备选居民区人数");
            data.put("data", dataRowsN);
            dataRows.add(data);

            table.put("table", dataRows);
        }
        return ajaxJson(table);
    }

    /**
     * 获取居民区书记一肩挑人员
     * @return
     */
    @RequestMapping(value = "getSjYjt", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object getSjYjt(String streetNo, String isBx, String type){
        System.out.println("请求 居民区书记 一肩挑人员 streetNo:" + streetNo);

        Map<String, Object> table = new HashMap<String, Object>();
        Map<String, Object> data;
        DictItem beixuan = beiXuan();
        List<Rule> rules = new ArrayList<Rule>();
        rules.add(RuleHelper.eq("shoulder", 1));
        rules.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        rules.add(RuleHelper.isNotNull("personNature"));

        if("before".equals(type)){
            rules.add(RuleHelper.eq("generalDict", getGeneralBefore())); //换届前
        }else{
            rules.add(RuleHelper.eq("generalDict", getGeneralAfter())); //换届后
        }

        if("1".equals(isBx)){
            rules.add(RuleHelper.eq("personNature", beixuan)); //备选书记
        }else{
            rules.add(RuleHelper.ne("personNature", beixuan)); //居民区书记
        }

        List<Person> personList = personService.findPerson(rules);

        List<Map<String, Object>> JsonList = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;
        int i=0;
        for(Person person:personList){
            if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("已一肩挑")){
                rMap = new HashMap<String, Object>();
                rMap.put("id", ++i);
                rMap.put("noteid", person.getId());
                rMap.put("txtName", StringUtils.isNotEmpty(person.getName())?person.getName():"");
                dataRows.add(rMap);
            }
        }
        data = new HashMap<String, Object>();
        data.put("txtType", "居民区书记一肩挑人员");
        data.put("data", dataRows);
        JsonList.add(data);

        table.put("table", JsonList);
        System.out.println("==完成");
        return ajaxJson(table);
    }

    /**
     * 获取书记拟一肩挑人员 （只有换届前有这个）
     * @param isBx 是否是备选书记   0||null不是   1是
     * @return
     */
    @RequestMapping(value = "getSjNyjt", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object getSjNyjt(String streetNo, String isBx){
        System.out.println("请求 居民区书记 拟一肩挑人员 streetNo:"+streetNo);

        Map<String, Object> table = new HashMap<String, Object>();
        Map<String, Object> data;
        List<Map<String, Object>> JsonList = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;

        DictItem beixuan = beiXuan();
        List<Rule> rules = new ArrayList<Rule>();
        rules.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        rules.add(RuleHelper.eq("shoulder", 1));
        rules.add(RuleHelper.eq("generalDict", getGeneralBefore()));
        if("1".equals(isBx)){
//            rules.add(RuleHelper.eq("personNature", beixuan));
        }else{
            rules.add(RuleHelper.ne("personNature", beixuan));
        }
        List<Person> personList = personService.findPerson(rules);
        int i=0;
        for(Person person:personList){
            if("1".equals(isBx)){ //备选书记
                if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("拟一肩挑备选")){
                    rMap = new HashMap<String, Object>();
                    rMap.put("id", ++i);
                    rMap.put("noteid", person.getId());
                    rMap.put("txtName", StringUtils.isNotEmpty(person.getName())?person.getName():"");
                    dataRows.add(rMap);
                }
            }else{ //居民区书记
                if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("拟一肩挑连任")){
                    rMap = new HashMap<String, Object>();
                    rMap.put("id", ++i);
                    rMap.put("noteid", person.getId());
                    rMap.put("txtName", StringUtils.isNotEmpty(person.getName())?person.getName():"");
                    dataRows.add(rMap);
                }
            }

        }
        data = new HashMap<String, Object>();
        data.put("txtType", "1".equals(isBx)?"备选书记拟一肩挑人员":"居民区书记拟一肩挑人员");
        data.put("data", dataRows);
        JsonList.add(data);

        table.put("table", JsonList);
        System.out.println("完成");
        return ajaxJson(table);
    }

    /**
     * 获取主任一肩挑人员
     * @return
     */
    @RequestMapping(value = "getZrYjt", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object getZrYjt(String streetNo){
        System.out.println("请求 主任 一肩挑人员 streetNo:"+streetNo);

        Map<String, Object> table = new HashMap<String, Object>();
        Map<String, Object> data;
        List<Rule> rules = new ArrayList<Rule>();
        rules.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        List<Director> personList = directorService.findPerson(rules);

        List<Map<String, Object>> JsonList = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;
        int i=0;
        for(Director person:personList){
            if(person.getShoulder()==1 && StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("已一肩挑")){
                rMap = new HashMap<String, Object>();
                rMap.put("id", ++i);
                rMap.put("noteid", person.getId());
                rMap.put("txtName", person.getName());
                dataRows.add(rMap);
            }
        }
        data = new HashMap<String, Object>();
        data.put("txtType", "居委会主任一肩挑人员");
        data.put("data", dataRows);
        JsonList.add(data);

        table.put("table", JsonList);
        System.out.println("==完成");
        return ajaxJson(table);
    }

    /**
     * 获取主任拟一肩挑人员
     * @return
     */
    @RequestMapping(value = "getZrNyjt", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object getZrNyjt(String streetNo){
        System.out.println("请求 主任 一肩挑人员 streetNo:"+streetNo);

        Map<String, Object> table = new HashMap<String, Object>();
        Map<String, Object> data;
        List<Rule> rules = new ArrayList<Rule>();
        rules.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        rules.add(RuleHelper.eq("shoulder", 1));
        List<Director> personList = directorService.findPerson(rules);

        List<Map<String, Object>> JsonList = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> rMap;
        int i=0;
        for(Director person:personList){
            if(StringUtils.isNotEmpty(person.getShoulderDet()) && person.getShoulderDet().contains("拟一肩挑备选")){
                rMap = new HashMap<String, Object>();
                rMap.put("id", ++i);
                rMap.put("noteid", person.getId());
                rMap.put("txtName", person.getName());
                dataRows.add(rMap);
            }
        }
        data = new HashMap<String, Object>();
        data.put("txtType", "居委会主任拟一肩挑人员");
        data.put("data", dataRows);
        JsonList.add(data);

        table.put("table", JsonList);
        System.out.println("==完成");
        return ajaxJson(table);
    }




    //获取备选书记系统字典
    public DictItem beiXuan(){
        DictItem beixuan = null;
        Dict personNature = dictService.getByValue("personNature");
        if(personNature!=null){
            beixuan = dictItemService.getByValue(personNature.getId(), "shujihoubei");
        }
        return beixuan;
    }

    /**
     * 书记 - 学历全区
     * @return
     */
    @RequestMapping(value = "sjEduAll", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object sjEduAll(String streetNo){
        System.out.println("请求 书记-学历全区 --- streetId:"+streetNo);
        DecimalFormat df = new DecimalFormat("0.00%");
        DictItem generalAfter = getGeneralAfter();

        User user = userService.getAll().get(0);
        List<DictItem> eduList = getDictItems(user, "edu");

        List<Map<String, Object>> list0 = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> list1 = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> list3 = new ArrayList<Map<String, Object>>();

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> data;
        List<Map<String, Object>> dataJsonList = new ArrayList<Map<String, Object>>();
        Map<String, Object> dataJson = new HashMap<String, Object>();
        Map<String, Object> rMap;

        List<Rule> rules = new ArrayList<Rule>();
        rules.add(RuleHelper.eq("generalDict", getGeneralAfter()));
        if(StringUtils.isNotEmpty(streetNo)){
            rules.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        }
        int allCount = personService.findPerson(rules).size();//所有人数
        BigDecimal allCountB = new BigDecimal(allCount);

        int beixuan = personService.getBeiXuanCount(true, beiXuan(), generalAfter); //备选人数
        int juminqu = personService.getBeiXuanCount(false, beiXuan(), generalAfter); //居民区人数
        BigDecimal beiXuanCount = new BigDecimal(beixuan);
        BigDecimal juMinQuCount = new BigDecimal(juminqu);

        //居民区书记
        for(DictItem edu:eduList){
            rMap = new HashMap<String, Object>();
            int count = 0;
            if(StringUtils.isEmpty(streetNo)){
                count = personService.getCountEduAll(false,beiXuan(),edu, generalAfter);
            }else{
                count = personService.getCountEduAll(false,beiXuan(),edu,residentService.getStreetByNo(Integer.parseInt(streetNo)), generalAfter);
            }

            rMap.put("txtXL", edu.getName());
            rMap.put("numXL", count);
            if(juminqu!=0){
                rMap.put("numBL", df.format(new BigDecimal(count).divide(juMinQuCount,2,BigDecimal.ROUND_UP)));
            }else{
                rMap.put("numBL", "0%");
            }
            list0.add(rMap);
        }
        data = new HashMap<String, Object>();
        data.put("type", "居民区书记");
        data.put("Indata", list0);
        dataJsonList.add(data);

        //备选书记
        for(DictItem edu:eduList){
            rMap = new HashMap<String, Object>();
            int count = 0;
            if(StringUtils.isEmpty(streetNo)){
                count = personService.getCountEduAll(true,beiXuan(),edu, generalAfter);
            }else{
                count = personService.getCountEduAll(true,beiXuan(),edu,residentService.getStreetByNo(Integer.parseInt(streetNo)), generalAfter);
            }
            rMap.put("txtXL", edu.getName());
            rMap.put("numXL", count);
            if(beixuan!=0){
                rMap.put("numBL", df.format(new BigDecimal(count).divide(beiXuanCount,2,BigDecimal.ROUND_UP)));
            }else{
                rMap.put("numBL", "0%");
            }
            list1.add(rMap);
        }
        data = new HashMap<String, Object>();
        data.put("type", "备选书记");
        data.put("Indata", list1);
        dataJsonList.add(data);

        //小计
        for(DictItem edu:eduList){
            rMap = new HashMap<String, Object>();
            int count = 0;
            if(StringUtils.isEmpty(streetNo)){
                count = personService.getCountEduAll(edu, generalAfter);
            }else{
                count = personService.getCountEduAll(edu,residentService.getStreetByNo(Integer.parseInt(streetNo)), generalAfter);
            }
            rMap.put("txtXL", edu.getName());
            rMap.put("numXL", count);
            if(allCount!=0){
                rMap.put("numBL", df.format(new BigDecimal(count).divide(allCountB,2,BigDecimal.ROUND_UP)));
            }else{
                rMap.put("numBL", "0%");
            }
            list3.add(rMap);
        }
        data = new HashMap<String, Object>();
        data.put("type", "小计");
        data.put("Indata", list3);
        dataJsonList.add(data);

        rMap = new HashMap<String, Object>();
        rMap.put("txtXL", "");
        rMap.put("numXL", String.valueOf(allCount));
        rMap.put("numBL", "");
        dataRows.add(rMap);

        data = new HashMap<String, Object>();
        data.put("type", "合计");
        data.put("Indata", dataRows);
        dataJsonList.add(data);

        dataJson.put("data", dataJsonList);

        return ajaxJson(dataJson);
    }


    /**
     * 性别年龄-全区  （如果streetId不为空，那就是年龄性别-街道）
     */
    @RequestMapping(value = "sjAgeAll", method = RequestMethod.POST, produces = MediaType.TEXT_HTML_VALUE)
    public Object ageAll(String streetNo){
        System.out.println("请求 书记-性别年龄-全区 --- streetId:"+streetNo);
        DecimalFormat df = new DecimalFormat("0.00%");
        DictItem generalAfter = getGeneralAfter();

        Map<String, Object> dataJson = new HashMap<String, Object>();
        List<Map<String, Object>> jsonList = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> list1 = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> list2 = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> list3 = new ArrayList<Map<String, Object>>();

        Map<String, Object> data;
        Map<String, Object> rMap;


        List<Rule> rules0 = new ArrayList<Rule>();
        rules0.add(RuleHelper.ne("personNature", beiXuan()));
        rules0.add(RuleHelper.eq("gender", "男"));
        rules0.add(RuleHelper.eq("state", BaseEnum.StateEnum.Enable));
        rules0.add(RuleHelper.eq("generalDict", generalAfter));
        if(StringUtils.isNotEmpty(streetNo)){
            rules0.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        }
        Long nan2 = personService.findCountBySearch(rules0).getCount(); //居民区书记男人数

        List<Rule> rules1 = new ArrayList<Rule>();
        rules1.add(RuleHelper.ne("personNature", beiXuan()));
        rules1.add(RuleHelper.eq("gender", "女"));
        rules1.add(RuleHelper.eq("state", BaseEnum.StateEnum.Enable));
        rules1.add(RuleHelper.eq("generalDict", generalAfter));
        if(StringUtils.isNotEmpty(streetNo)){
            rules1.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        }
        Long nv2 = personService.findCountBySearch(rules1).getCount(); //居民区书记女人数

        List<Rule> rules3 = new ArrayList<Rule>();
        rules3.add(RuleHelper.eq("personNature", beiXuan()));
        rules3.add(RuleHelper.eq("gender", "男"));
        rules3.add(RuleHelper.eq("state", BaseEnum.StateEnum.Enable));
        rules3.add(RuleHelper.eq("generalDict", generalAfter));
        if(StringUtils.isNotEmpty(streetNo)){
            rules3.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        }
        Long nan1 = personService.findCountBySearch(rules3).getCount(); //备选书记男人数

        List<Rule> rules4 = new ArrayList<Rule>();
        rules4.add(RuleHelper.eq("personNature", beiXuan()));
        rules4.add(RuleHelper.eq("gender", "女"));
        rules4.add(RuleHelper.eq("state", BaseEnum.StateEnum.Enable));
        rules4.add(RuleHelper.eq("generalDict", generalAfter));
        if(StringUtils.isNotEmpty(streetNo)){
            rules4.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        }
        Long nv1 = personService.findCountBySearch(rules4).getCount(); //备选书记女人数

        List<Rule> rules5 = new ArrayList<Rule>();
        rules5.add(RuleHelper.eq("gender", "男"));
        rules5.add(RuleHelper.eq("state", BaseEnum.StateEnum.Enable));
        rules5.add(RuleHelper.eq("generalDict", generalAfter));
        if(StringUtils.isNotEmpty(streetNo)){
            rules5.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        }
        Long nan0 = personService.findCountBySearch(rules5).getCount(); //合计男人数

        List<Rule> rules6 = new ArrayList<Rule>();
        rules6.add(RuleHelper.eq("gender", "女"));
        rules6.add(RuleHelper.eq("state", BaseEnum.StateEnum.Enable));
        rules6.add(RuleHelper.eq("generalDict", generalAfter));
        if(StringUtils.isNotEmpty(streetNo)){
            rules6.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        }
        Long nv0 = personService.findCountBySearch(rules6).getCount(); //合计女人数

        int age1 = 0;
        int age2 = 0;
        int age0 = 0;

//        int beixuan = personService.getBeiXuanCount(true, beiXuan());
//        int juminqu = personService.getBeiXuanCount(false, beiXuan());
        int beixuan = Integer.parseInt(nan1.toString())+Integer.parseInt(nv1.toString());
        int juminqu = Integer.parseInt(nan2.toString())+Integer.parseInt(nv2.toString());
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("state", BaseEnum.StateEnum.Enable);
        params.put("generalDict", generalAfter);
        if(StringUtils.isNotEmpty(streetNo)){
            params.put("street", residentService.getStreetByNo(Integer.parseInt(streetNo)));
        }
        List<Person> personList = personService.getList(params); //当前总人数
        for(Person person:personList){
            int thisAge = getAge(person.getBirthday());
            age0+=thisAge;
            if("shujihoubei".equals(person.getPersonNature()==null?"":person.getPersonNature().getValue())){
                age1+=thisAge;
            }else{
                age2+=thisAge;
            }
        }

        BigDecimal ageB1 = new BigDecimal(age1);
        BigDecimal ageB2 = new BigDecimal(age2);
        BigDecimal ageB0 = new BigDecimal(age0);

        BigDecimal countB1 = new BigDecimal(beixuan); //备选总人数
        BigDecimal countB2 = new BigDecimal(juminqu); //居民区总人数
        BigDecimal countB0 = new BigDecimal(personList.size()); //当前总人数

        BigDecimal beiXuanCount = new BigDecimal(beixuan);
        BigDecimal juMinQuCount = new BigDecimal(juminqu);


        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "男");
        rMap.put("numXX", String.valueOf(nan2));
        rMap.put("numBL", juminqu == 0 ? "0%" : df.format(new BigDecimal(nan2).divide(juMinQuCount, 2, BigDecimal.ROUND_UP)));
        list1.add(rMap);

        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "女");
        rMap.put("numXX", String.valueOf(nv2));
        rMap.put("numBL", juminqu == 0 ? "0%" : df.format(new BigDecimal(nv2).divide(juMinQuCount, 2, BigDecimal.ROUND_UP)));
        list1.add(rMap);

        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "平均年龄");
        rMap.put("numXX", juminqu == 0 ? "" : String.valueOf(ageB2.divide(countB2, 2, BigDecimal.ROUND_UP)));
        rMap.put("numBL", "");
        list1.add(rMap);

        data = new HashMap<String, Object>();
        data.put("type", "居民区书记");
        data.put("Indata", list1);
        jsonList.add(data);


        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "男");
        rMap.put("numXX", String.valueOf(nan1));
        rMap.put("numBL", beixuan == 0 ? "0%" : df.format(new BigDecimal(nan1).divide(beiXuanCount, 2, BigDecimal.ROUND_UP)));
        list2.add(rMap);

        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "女");
        rMap.put("numXX", String.valueOf(nv1));
        rMap.put("numBL", beixuan == 0 ? "0%" : df.format(new BigDecimal(nv1).divide(beiXuanCount, 2, BigDecimal.ROUND_UP)));
        list2.add(rMap);

        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "平均年龄");
        rMap.put("numXX", beixuan == 0 ? "" : String.valueOf(ageB1.divide(countB1, 2, BigDecimal.ROUND_UP)));
        rMap.put("numBL", "");
        list2.add(rMap);

        data = new HashMap<String, Object>();
        data.put("type", "备选书记");
        data.put("Indata", list2);
        jsonList.add(data);


        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "男");
        rMap.put("numXX", String.valueOf(nan0));
        rMap.put("numBL", personList.size() == 0 ? "0%" : df.format(new BigDecimal(nan0).divide(countB0, 2, BigDecimal.ROUND_UP)));
        list3.add(rMap);

        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "女");
        rMap.put("numXX", String.valueOf(nv0));
        rMap.put("numBL", personList.size() == 0 ? "0%" : df.format(new BigDecimal(nv0).divide(countB0, 2, BigDecimal.ROUND_UP)));
        list3.add(rMap);

        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "平均年龄");
        rMap.put("numXX", personList.size() == 0 ? "" : String.valueOf(ageB0.divide(countB0, 2, BigDecimal.ROUND_UP)));
        rMap.put("numBL", "");
        list3.add(rMap);

        data = new HashMap<String, Object>();
        data.put("type", "备选书记");
        data.put("Indata", list3);
        jsonList.add(data);

        dataJson.put("data", jsonList);

        return ajaxJson(dataJson);
    }


    /**
     * 人员性质-全区 （如果streetId不为空，那就是 人员性质-街道）
     */
    @RequestMapping(value = "sjNatureAll", method = RequestMethod.POST, produces = MediaType.TEXT_HTML_VALUE)
    public Object sjNatureAll(String streetNo){
        System.out.println("请求 书记-人员性质-全区 --- streetNo:"+streetNo);
        DictItem generalAfter = getGeneralAfter();
        DecimalFormat df = new DecimalFormat("0.00%");

        Map<String, Object> dataJson = new HashMap<String, Object>();
        List<Map<String, Object>> jsonList = new ArrayList<Map<String, Object>>();

        Map<String, Object> data;
        Map<String, Object> rMap;


        DictItem street = null;
        if(StringUtils.isNotEmpty(streetNo)){
            street = residentService.getStreetByNo(Integer.parseInt(streetNo));
        }

        int allCount = 0;
        if(street==null){
            allCount = personService.getAllCount(generalAfter);
        }else{
            allCount = personService.getCountByStreet(street, generalAfter);
        }

        BigDecimal allCountB = new BigDecimal(allCount);
        List<Map<String, Object>> list;
        int beixuanCount = 0;

        User user = userService.getAll().get(0);
        List<DictItem> personNature = getDictItems(user, "personNature");
        list = new ArrayList<Map<String, Object>>();
        for(DictItem nature:personNature){

            int count = 0;
            if(street==null){
                count = personService.getCountByPersonNature(nature, generalAfter);
            }else{
                count = personService.getCountByNatureAndStreet(nature, street, generalAfter);
            }

            if("shujihoubei".equals(nature.getValue())){
                beixuanCount = count;
            }else{
                rMap = new HashMap<String, Object>();
                rMap.put("txtXX", nature.getName());
                rMap.put("numXX", count);
                rMap.put("numBL", allCount==0 ? "0%" : df.format(new BigDecimal(count).divide(allCountB,2,BigDecimal.ROUND_UP)));
                list.add(rMap);
            }
        }
        data = new HashMap<String, Object>();
        data.put("type", "居民区书记");
        data.put("Indata", list);
        jsonList.add(data);

        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "");
        rMap.put("numXX", beixuanCount);
        rMap.put("numBL", "");
        list = new ArrayList<Map<String, Object>>();
        list.add(rMap);

        data = new HashMap<String, Object>();
        data.put("type", "备选书记");
        data.put("Indata", list);
        jsonList.add(data);

        if(StringUtils.isNotEmpty(streetNo)){
            Dict xingzhi = dictService.getByValue("personNature");
            DictItem tuixiufanpin = null;
            if(xingzhi!=null){
                tuixiufanpin = dictItemService.getByValue(xingzhi.getId(),"tuixiufanpin");
            }

            DictItem streeta = residentService.getStreetByNo(Integer.parseInt(streetNo));
            List<Resident> residentList = residentService.getResidentByStreet(residentService.getStreetByNo(Integer.parseInt(streetNo)));
            int fanPinCount = personService.getHuanJieCountByStreet(streeta, tuixiufanpin, generalAfter).size();
            int juMinQuCount = residentList.size();
            BigDecimal aB = new BigDecimal(juMinQuCount).multiply(new BigDecimal(0.3));
            BigDecimal re = new BigDecimal(fanPinCount).subtract(aB);

            rMap = new HashMap<String, Object>();
            rMap.put("txtXX", "");
            rMap.put("numXX", re.setScale(0, BigDecimal.ROUND_UP));
            rMap.put("numBL", "");
            list = new ArrayList<Map<String, Object>>();
            list.add(rMap);

            data = new HashMap<String, Object>();
            data.put("type", "换届应调整人数");
            data.put("Indata", list);
            jsonList.add(data);
        }


        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "");
        rMap.put("numXX", String.valueOf(allCount));
        rMap.put("numBL", "");
        list = new ArrayList<Map<String, Object>>();
        list.add(rMap);

        data = new HashMap<String, Object>();
        data.put("type", "合计");
        data.put("Indata", list);
        jsonList.add(data);

        dataJson.put("data", jsonList);

        return ajaxJson(dataJson);
    }



    // ======================主任=============================


    /**
     * 根据性别分类
     * @param streetNo 街道编号 0-11
     * @return
     */
    @RequestMapping(value = "getZrGender", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public Object getZrGender(Integer streetNo){
        System.out.println("请求 主任-根据性别分类 --- streetNo:"+streetNo);
        if(streetNo==null){
            return ajaxText("streetNo为空");
        }

        DictItem street = residentService.getStreetByNo(streetNo);
        Map<String, Object> table = new HashMap<String, Object>();
        if(street!=null){
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("state", BaseEnum.StateEnum.Enable);
            params.put("street", street);
            List<Director> personList = directorService.getList(params);

            int i=0;
            int j=0;
            Map<String, Object> data;
            Map<String, Object> rMap;
            List<Map<String, Object>> dataRowsNan = new ArrayList<Map<String, Object>>();
            List<Map<String, Object>> dataRowsNv = new ArrayList<Map<String, Object>>();

            List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
            for(Director person:personList){

                rMap = new HashMap<String, Object>();
                rMap.put("noteid", person.getId());
                rMap.put("numAge", person.getBirthday() != null ? String.valueOf(getAge(person.getBirthday())) : "");
                rMap.put("txtName", StringUtils.isNotEmpty(person.getName())?person.getName():"");
                if("男".equals(person.getGender())){
                    i++;
                    rMap.put("id", String.valueOf(i));
                    dataRowsNan.add(rMap);
                }else{
                    j++;
                    rMap.put("id", String.valueOf(j));
                    dataRowsNv.add(rMap);
                }
            }

            data = new HashMap<String, Object>();
            data.put("data", dataRowsNv);
            data.put("txtType", "女");
            dataRows.add(data);

            data = new HashMap<String, Object>();
            data.put("data", dataRowsNan);
            data.put("txtType", "男");
            dataRows.add(data);

            table.put("table", dataRows);
        }
        return ajaxJson(table);
    }

    /**
     * 主任 根据大专分类
     * @return
     */
    @RequestMapping(value = "getZrEdu", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object getZrEdu(Integer streetNo){
        System.out.println("请求 主任 根据大专分类 --- streetNo:"+streetNo);
        if(streetNo==null){
            return ajaxText("streetNo为空");
        }

        DictItem street = residentService.getStreetByNo(streetNo);
        Map<String, Object> table = new HashMap<String, Object>();
        if(street!=null) {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("state", BaseEnum.StateEnum.Enable);
            params.put("street", street);
            List<Director> personList = directorService.getList(params);

            int i = 1;
            int j = 1;
            Map<String, Object> data;
            Map<String, Object> rMap;
            List<Map<String, Object>> dataRowsUp = new ArrayList<Map<String, Object>>();
            List<Map<String, Object>> dataRowsDown = new ArrayList<Map<String, Object>>();
            List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();

            for (Director person : personList) {
                rMap = new HashMap<String, Object>();
                rMap.put("noteid", person.getId());
                rMap.put("txtName", StringUtils.isNotEmpty(person.getName()) ? person.getName() : "");
                rMap.put("txtEducation", person.getHighEdu() != null ? person.getHighEdu().getName() : "");
                if (person.getHighEdu() != null) {
                    String eduId = person.getHighEdu().getId();
                    if (eduId.equals(person.getAllDaySchool())) {
                        rMap.put("txtXZ", "全日制教育");
                    } else {
                        rMap.put("txtXZ", "在职教育");
                    }
                }
                rMap.put("txtSex", StringUtils.isNotEmpty(person.getGender()) ? person.getGender() : "");
                String eduVal = person.getHighEdu() != null ? person.getHighEdu().getValue() : "";
                if ("edu4".equals(eduVal) || "edu5".equals(eduVal) || "edu6".equals(eduVal)) {
                    rMap.put("id", String.valueOf(i++));
                    dataRowsUp.add(rMap);
                } else {
                    rMap.put("id", String.valueOf(j++));
                    dataRowsDown.add(rMap);
                }
            }

            data = new HashMap<String, Object>();
            data.put("data", dataRowsUp);
            data.put("txtType", "大专及以上学历");
            dataRows.add(data);

            data = new HashMap<String, Object>();
            data.put("data", dataRowsDown);
            data.put("txtType", "大专以下学历");
            dataRows.add(data);

            table.put("table", dataRows);
        }
        return ajaxJson(table);
    }

    /**
     * 主任 学历
     * @return
     */
    @RequestMapping(value = "zrEduAll", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object getZrEdu(String streetNo){
        System.out.println("请求 主任 根据学历分类 --- streetNo:"+streetNo);
        DecimalFormat df = new DecimalFormat("0.00%");

        User user = userService.getAll().get(0);
        List<DictItem> eduList = getDictItems(user, "edu");

        List<Map<String, Object>> list3 = new ArrayList<Map<String, Object>>();

        List<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();
        Map<String, Object> data;
        List<Map<String, Object>> dataJsonList = new ArrayList<Map<String, Object>>();
        Map<String, Object> dataJson = new HashMap<String, Object>();

        Map<String, Object> rMap;

        List<Rule> rules = new ArrayList<Rule>();
        if(StringUtils.isNotEmpty(streetNo)){
            rules.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        }
        int allCount = directorService.findPerson(rules).size();//所有人数
        BigDecimal allCountB = new BigDecimal(allCount);

        //主任
        for(DictItem edu:eduList){
            rMap = new HashMap<String, Object>();
            int count = 0;
            if(StringUtils.isEmpty(streetNo)){
                count = directorService.getCountEduAll(edu);
            }else{
                count = directorService.getCountEduAll(edu,residentService.getStreetByNo(Integer.parseInt(streetNo)));
            }
            rMap.put("txtXL", edu.getName());
            rMap.put("numXL", count);
            if(allCount!=0){
                rMap.put("numBL", df.format(new BigDecimal(count).divide(allCountB,2,BigDecimal.ROUND_UP)));
            }else{
                rMap.put("numBL", "0%");
            }
            list3.add(rMap);
        }
        data = new HashMap<String, Object>();
        data.put("type", "主任");
        data.put("Indata", list3);
        dataJsonList.add(data);

        rMap = new HashMap<String, Object>();
        rMap.put("txtXL", "");
        rMap.put("numXL", String.valueOf(allCount));
        rMap.put("numBL", "");
        dataRows.add(rMap);

        data = new HashMap<String, Object>();
        data.put("type", "合计");
        data.put("Indata", dataRows);
        dataJsonList.add(data);

        dataJson.put("data", dataJsonList);

        return ajaxJson(dataJson);
    }

    /**
     * 主任 年龄性别
     * @return
     */
    @RequestMapping(value = "zrAgeAll", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object zrAgeAll(String streetNo){
        System.out.println("请求 主任 根据年龄分类 --- streetNo:"+streetNo);
        DecimalFormat df = new DecimalFormat("0.00%");

        Map<String, Object> dataJson = new HashMap<String, Object>();
        List<Map<String, Object>> jsonList = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> list3 = new ArrayList<Map<String, Object>>();

        Map<String, Object> data;
        Map<String, Object> rMap;

        List<Rule> rules5 = new ArrayList<Rule>();
        rules5.add(RuleHelper.eq("gender", "男"));
        rules5.add(RuleHelper.eq("state", BaseEnum.StateEnum.Enable));
        if(StringUtils.isNotEmpty(streetNo)){
            rules5.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        }
        Long nan0 = directorService.findCountBySearch(rules5).getCount(); //合计男人数

        List<Rule> rules6 = new ArrayList<Rule>();
        rules6.add(RuleHelper.eq("gender", "女"));
        rules6.add(RuleHelper.eq("state", BaseEnum.StateEnum.Enable));
        if(StringUtils.isNotEmpty(streetNo)){
            rules6.add(RuleHelper.eq("street", residentService.getStreetByNo(Integer.parseInt(streetNo))));
        }
        Long nv0 = directorService.findCountBySearch(rules6).getCount(); //合计女人数

        int age0 = 0;

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("state", BaseEnum.StateEnum.Enable);
        if(StringUtils.isNotEmpty(streetNo)){
            params.put("street", residentService.getStreetByNo(Integer.parseInt(streetNo)));
        }
        List<Director> directorList = directorService.getList(params); //当前总人数
        for(Director person:directorList){
            int thisAge = getAge(person.getBirthday());
            age0+=thisAge;
        }

        BigDecimal ageB0 = new BigDecimal(age0);
        BigDecimal countB0 = new BigDecimal(directorList.size()); //当前总人数


        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "男");
        rMap.put("numXX", String.valueOf(nan0));
        rMap.put("numBL", directorList.size() == 0 ? "0%" : df.format(new BigDecimal(nan0).divide(countB0, 2, BigDecimal.ROUND_UP)));
        list3.add(rMap);

        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "女");
        rMap.put("numXX", String.valueOf(nv0));
        rMap.put("numBL", directorList.size() == 0 ? "0%" : df.format(new BigDecimal(nv0).divide(countB0, 2, BigDecimal.ROUND_UP)));
        list3.add(rMap);

        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "平均年龄");
        rMap.put("numXX", directorList.size() == 0 ? "" : String.valueOf(ageB0.divide(countB0, 2, BigDecimal.ROUND_UP)));
        rMap.put("numBL", "");
        list3.add(rMap);

        data = new HashMap<String, Object>();
        data.put("type", "性别年龄");
        data.put("Indata", list3);
        jsonList.add(data);

        dataJson.put("data", jsonList);

        return ajaxJson(dataJson);
    }

    /**
     * 主任 党员性质
     * @return
     */
    @RequestMapping(value = "zrNatureAll", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Object zrNatureAll(String streetNo){
        System.out.println("请求 主任 根据党员性质分类 --- streetNo:"+streetNo);
        DecimalFormat df = new DecimalFormat("0.00%");

        Map<String, Object> dataJson = new HashMap<String, Object>();
        List<Map<String, Object>> jsonList = new ArrayList<Map<String, Object>>();

        Map<String, Object> data;
        Map<String, Object> rMap;

        DictItem street = null;
        if(StringUtils.isNotEmpty(streetNo)){
            street = residentService.getStreetByNo(Integer.parseInt(streetNo));
        }

        int allCount = 0;
        if(street==null){
            allCount = directorService.getAllCount();
        }else{
            allCount = directorService.getCountByStreet(street);
        }

        BigDecimal allCountB = new BigDecimal(allCount);
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

        List<Rule> rules = new ArrayList<Rule>();
        if(StringUtils.isNotEmpty(streetNo)){
            rules.add(RuleHelper.eq("street", street));
        }
        rules.add(RuleHelper.isNotNull("joinPartyDate"));
        int dangyuanCount = directorService.findPerson(rules).size(); //党员数量
        int feidangyuanCount = allCount - dangyuanCount; //非党员数量

        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "党员数量");
        rMap.put("numXX", String.valueOf(dangyuanCount));
        rMap.put("numBL", allCount==0 ? "0%" : df.format(new BigDecimal(dangyuanCount).divide(allCountB,2,BigDecimal.ROUND_UP)));
        list.add(rMap);

        rMap = new HashMap<String, Object>();
        rMap.put("txtXX", "非党员数量");
        rMap.put("numXX", String.valueOf(feidangyuanCount));
        rMap.put("numBL", allCount == 0 ? "0%" : df.format(new BigDecimal(feidangyuanCount).divide(allCountB, 2, BigDecimal.ROUND_UP)));
        list.add(rMap);

        data = new HashMap<String, Object>();
        data.put("type", "党员性质");
        data.put("Indata", list);
        jsonList.add(data);

        dataJson.put("data", jsonList);

        return ajaxJson(dataJson);
    }




}
